mui.previewImage();
    var specifications;
    var id = getUrlParam('id');
    $.ajax({
        type: "get",
        url: Url + "product/" + id,
        async: false,
        timeout : 20000,
        beforeSend: function (xhr) {
            showDiv()
        },
        success: function (data) {
            hiddenDiv()
            console.log(data);
            specifications = data.product[0].specifications;
            var productImg = data.product[0].products_img;
            console.log(productImg);
            var str1 = '<div class="mui-slider-item mui-slider-item-duplicate">'
                + '<img src="' + productImg[productImg.length - 1].pimg_url + '" data-preview-src="" data-preview-group="1"/>'
                + '</div>';
            var str2 = '';
            $(productImg).each(function (k, v) {
                str1 += '<div class="mui-slider-item">'
                    + '<img src="' + v['pimg_url'] + '" data-preview-src="" data-preview-group="1"/>'
                    + '</div>';
                str2 += '<div class="mui-indicator"></div>'
            })
            str1 += '<div class="mui-slider-item mui-slider-item-duplicate">'
                + '<img src="' + productImg[0].pimg_url + '" data-preview-src="" data-preview-group="1"/>'
                + '</div>';
            var str = '<div class="mui-slider-group mui-slider-loop">' + str1 + '</div>'
                + '<div class="mui-slider-indicator">' + str2 + '</div>';
            $("#banner").html(str);
            $(".title").text(data.product[0].products_name);
            $(".title-two").text(data.product[0].products_introduction);
            $(".new-price").text("￥" + data.product[0].products_sellingprice);
            $(".old-price").text("￥" + data.product[0].products_marketprice);
            var strlabeling = '';
            $(data.product[0].labeling).each(function (k, v) {
                strlabeling += '<span class="discount">' + v.label_name + '</span>';
            })
            $(".summary-b").html(strlabeling)

            var counts=parseInt(data.count)+parseInt(data.counts);
            $(".evaluate-num").text(counts);
            $(".evaluate-t-title").text("用户评价("+counts+")");
            if (data.evaluate) {
                $(".evaluate-b-title").append(data.evaluate.user_id);
                var imgStarContent = '';
                if (data.evaluate.evaluate_states == 1) {
                    for (var i = 0; i < 5; i++) {
                        imgStarContent += '<img src="/static/index/img/starselected.png"/>';
                    }
                } else if (data.evaluate.evaluate_states == 2) {
                    for (var i = 0; i < 4; i++) {
                        imgStarContent += '<img src="/static/index/img/starselected.png"/>';
                    }
                } else if (data.evaluate.evaluate_states == 3) {
                    for (var i = 0; i < 3; i++) {
                        imgStarContent += '<img src="/static/index/img/starselected.png"/>';
                    }
                }
                $(".evaluate-b-time").find("div").eq(0).text(data.evaluate.createtime);
                $(".evaluate-b-time").find("div").eq(1).html(imgStarContent);
                var ebmContent = '<span>' + data.evaluate.evaluate + '</span>';
                if (data.evaluate.img_data.length != 0) {
                    for (var i = 0; i < data.evaluate.img_data.length; i++) {
                        ebmContent += '<img src="' + data.evaluate.img_data[0].eimg_url + '"/>'
                    }
                }

                var ebnContent = data.product[0].products_name;
                for (var key in data.evaluate.speci_snap) {
                    ebnContent += '<span>' + key + ':' + data.evaluate.speci_snap[key] + '</span>'
                }
                $(".evaluate-b-main").html(ebmContent);
                $(".evaluate-b-name").html(ebnContent);
            }
            $(".goods_ids").val(data.product[0].products_id);
            $(".cmt-name").html(data.product[0].products_name);
            $(".qsm-goods-img").attr("src", data.product[0].recommend);
            $(".qsm-goods-varieties").text('￥' + data.product[0].products_sellingprice);
            var specificationsList = '';
            $(data.product[0].speci).each(function (k, v) {
                var str = '';
                for (var i = 0; i < v.pspecifications.length; i++) {
                    str += '<span data-id="' + v.pspecifications[i].element + '" data-imgurl="' + v.pspecifications[i].img + '" onclick="specificationsSelection(this)">' + v.pspecifications[i].element + '</span>'
                }
                specificationsList += '<div class="specifications">'
                    + '<div class="specifications-title">' + v.pspecifications_type + '</div>'
                    + '<div class="evaluate-title-txt clear">'
                    + str
                    + '</div>'
                    + '</div>';
            })
            $(".detail_url").attr('src', data.product[0].details.pdetails_url)
            $(".quantity-specification-main").prepend(specificationsList);
        },
        error: function (request, status, err) {
            failure(status)
        }
    });
    mui.init({
        swipeBack: true //启用右滑关闭功能
    });
    var slider = mui("#banner");
    slider.slider({
        interval: 2000
    });

    function specificationsSelection(that) {
        if ($(that).attr("data-imgurl")) {
            $(".qsm-goods-img").attr("src", $(that).attr("data-imgurl"));
        }
        $(".qsm-goods-price").children("span").text("");
        $(".spe-title").children("s").text("");
        $(that).addClass("thisOn").siblings().removeClass("thisOn");
        var selectionSpan = $(".evaluate-title-txt").children("span");
        for (var i = 0; i < selectionSpan.length; i++) {
            if (selectionSpan.eq(i).hasClass("thisOn")) {
                $(".qsm-goods-price").children("span").append("<b>" + selectionSpan.eq(i).text() + "</b>,");
                $(".spe-title").children("s").append(selectionSpan.eq(i).text() + ",")
            }
        }
        var arr = [];
        var qgpHtml = $(".qsm-goods-price").children("span").children("b");
        var ettHtml = $(".evaluate-title-txt")
        if (ettHtml.length == qgpHtml.length) {
            for (var i = 0; i < qgpHtml.length; i++) {
                arr.push(qgpHtml.eq(i).text())
            }
            for (var i = 0; i < specifications.length; i++) {
                if (arr.sort().toString() == specifications[i].pspeci_element.sort().toString()) {
                    var pspeci_id = specifications[i].pspeci_id
                    //请求后台，看是否有库存
                    is_pspeci_stock(pspeci_id)
                }
            }
        }
    }

//查询后台库存情况
    function is_pspeci_stock(id) {
        $.ajax({
            type: "get",
            url: Url + "specifi/" + id,
            async: false,
            timeout : 20000,
            beforeSend: function (xhr) {
                showDiv()
            },
            success: function (data) {
                hiddenDiv()
                console.log(data);
                //修改价格//保存规格id
                $(".qsm-goods-varieties").text("￥" + data['pspeci_price']);
                $(".pspeci_ids").val(data['pspeci_id']);
                if (data['pspeci_stock']) {
                    $(".sellOut").css("display", "none").siblings().css("display", "block")
                } else {
                    $(".sellOut").css("display", "block").siblings().css("display", "none")
                }
            },
            error: function (request, status, err) {
                failure(status)
            }
        })
    }

    function addCarts() {
        var ettHtml = $(".evaluate-title-txt")
        var qgpHtml = $(".qsm-goods-price").children("span").children("b");
        if (ettHtml.length != qgpHtml.length) {
            taostr("请选择规格", 1000);
            $(".quantity-specification").show()
            $(".spe-title").children("b").text("×1")
            return;
        } else {
            //后台加入购物车//产品id//规格id
            var quantity = $('.goodsNum').val();
            var specif_id = $('.pspeci_ids').val();
            var products_id = $('.goods_ids').val();
            var cartData = {
                "products_id": products_id,
                "spe_id": specif_id,
                "num": quantity
            };
            console.log(cartData);
            //后台添加购物车
            SeverAddCart(cartData)
        }
    }

    $("#goPay").on('click', function () {
        var ettHtml = $(".evaluate-title-txt")
        var qgpHtml = $(".qsm-goods-price").children("span").children("b");
        if (ettHtml.length != qgpHtml.length) {
            taostr("请选择规格", 1000);
            $(".quantity-specification").show()
            $(".spe-title").children("b").text("×1")
            return;
        } else {
            //后台加入购物车//产品id//规格id
            var quantity = $('.goodsNum').val();
            var specif_id = $('.pspeci_ids').val();
            var products_id = $('.goods_ids').val();
            var cartData = {
                "products_id": products_id,
                "spe_id": specif_id,
                "num": quantity
            };
            console.log(cartData);
            //后台添加购物车
            userGoPay(cartData);
        }
    })

    function userGoPay(cartData) {
        $.ajax({
            type: "post",
            url: Url + "OrderCreate",
            data: cartData,
            async: false,
            timeout : 20000,
            beforeSend: function (xhr) {

                    showDiv()

                xhr.setRequestHeader("token", tokenk);
            },
            success: function (data) {
                hiddenDiv()
                console.log(data);
                storage.setItem("cartId", data);
                if (data) {
                    location.href = "checkout.html";
                } else if (data['errorCode'] == 10001) {
                    console.log(data['msg']);
                }
            },
            error: function (request, status, err) {
                failure(status)
            }
        })

    }

    function SeverAddCart(cartData) {
        $.ajax({
            type: "post",
            url: Url + "cart/data/",
            data: cartData,
            async: false,
            timeout : 20000,
            beforeSend: function (xhr) {

                    showDiv()

                xhr.setRequestHeader("token", tokenk);
            },
            success: function (data) {
                hiddenDiv()
                console.log(data);
                //添加购物车成功失败
                if (data) {
                    //返回状态表示添加成功
                    taostr('添加购物车成功', 1000);
                } else if (data['errorCode'] == 10001) {
                    taostr('添加购物车失败', 1000);
                }
            },
            error: function (request, status, err) {
                failure(status)
                taostr('添加购物车失败', 1000);
            }
        })
    }


    function bindMinus(that) {
        var num = $(that).next("input").val();
        if (num > 1) {
            num--;
        }
        $(that).next("input").val(num)
        $(".qsm-goods-price").children("s").text(num);
        $(".spe-title").children("b").text("×" + num)
    }

    function bindPlus(that) {
        var num = $(that).prev("input").val();
        num++;
        $(that).prev("input").val(num)
        $(".qsm-goods-price").children("s").text(num);
        $(".spe-title").children("b").text("×" + num)
    }

    var hrefText = location.href;
    $(".goodsNum").on("input", function () {
        var num = $(this).val();
        $(".spe-title").children("b").text("×" + num);
        $(".qsm-goods-price").children("s").text(num);
    });
    $(".goIndex").click(function () {
        location.href = hrefText.replace("goods_detail", "index")
    });
    $(".goCart").click(function () {
        location.href = hrefText.replace("goods_detail", "cart")
    });
    $(".evaluate-t").click(function () {

        //location.href=hrefText.replace("goods_detail","goods_evaluate")
        location.href = 'goods_evaluate.html?id=' + id;
    });
    $(".evaluate-look").click(function () {
        //location.href=hrefText.replace("goods_detail","goods_evaluate")
        location.href = 'goods_evaluate.html?id=' + id;
    });

    function showHtmlOne() {
        $(".quantity-specification").show()
    }

    function hideHtmlOne() {
        $(".quantity-specification").hide()
    }

    function showHtmlTwo() {
        $(".service-ejection").show()
    }

    function hideHtmlTwo() {
        $(".service-ejection").hide()
    }

//加入购物车
//点击立即结算
    $("#addCart").on("click", function () {
        //判断是否选择规格
        var ettHtml = $(".evaluate-title-txt");
        var qgpHtml = $(".qsm-goods-price").children("span").children("b");
        if (ettHtml.length == qgpHtml.length) {
            taostr('请选择规格', 1000);
            $(".quantity-specification").show();
            $(".spe-title").children("b").text("×1");
            return;
        }
        var cartData = {
            "products_id": this.data.products_id,
            "spe_id": this.data.specif_id,
            "num": this.data.quantity
        };
        console.log(cartData);
        this.insertCart(cartData);
    });

    var imgSrc="/static/index/img/erweima_1.jpg"
    $(".goService").on("click",function(){
        mask(imgSrc)
    })



